// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: xguo

#pragma once

#include <string>

#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
#include <rapidjson/schema.h>
#include <rapidjson/writer.h>

#include "coin2/exchange/base/executor/topic_publisher.h"

inline std::string JsonToString(const rapidjson::GenericValue<rapidjson::UTF8<>>& json) {
  rapidjson::StringBuffer buffer;
  buffer.Clear();
  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
  json.Accept(writer);
  return buffer.GetString();
}

inline bool JsonFieldCheck(const rapidjson::GenericValue<rapidjson::UTF8<>>& document, const std::vector<std::string>& fields){
  for(const auto& field : fields){
    if(!document.HasMember(field.c_str())){
      return false;
    }
  }
  return true;
}